package com.sqly.doc.util;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import com.cazaea.sweetalert.SweetAlertDialog;
import com.sqly.doc.menu.tnb.tnb;

public class SweetAlertDialogUtil {

    public static void WarningDialog(Context context, String titleText, String contentText) {
        SweetAlertDialog sd = new SweetAlertDialog(context, SweetAlertDialog.WARNING_TYPE);
        sd.setCancelable(true);
        sd.setCanceledOnTouchOutside(true);
        sd.setTitleText(null == titleText || "".equals(titleText) ? "提示" : titleText);
        sd.setContentText(null == contentText || "".equals(contentText) ? "不能为空" : contentText);
        sd.show();
    }

    public static void ErrorDialogNoFinish(final Context context, String titleText, String contentText, String confirmText) {
        new SweetAlertDialog(context, SweetAlertDialog.ERROR_TYPE)
                .setTitleText(null == titleText || "".equals(titleText) ? "提示" : titleText)
                .setContentText(null == contentText || "".equals(contentText) ? "不能为空" : contentText)
                .setConfirmText(confirmText)
                .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
                    @Override
                    public void onClick(SweetAlertDialog sweetAlertDialog) {
                        sweetAlertDialog.dismissWithAnimation();
                    }
                })
                .show();;
    }

    public static void ErrorDialog(final Context context, String titleText, String contentText, String confirmText) {
        new SweetAlertDialog(context, SweetAlertDialog.ERROR_TYPE)
                .setTitleText(null == titleText || "".equals(titleText) ? "提示" : titleText)
                .setContentText(null == contentText || "".equals(contentText) ? "不能为空" : contentText)
                .setConfirmText(confirmText)
                .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
                    @Override
                    public void onClick(SweetAlertDialog sweetAlertDialog) {
                        sweetAlertDialog.dismissWithAnimation();
                        ((Activity)context).finish();
                    }
                })
                .show();;
    }

    public static void WarningDialogHaveCancelAndConfirm(final Context context, String titleText,String contentText, String cancelText, String confirmText){
        new SweetAlertDialog(context, SweetAlertDialog.WARNING_TYPE)
                .setTitleText(null == titleText || "".equals(titleText) ? "提示" : titleText)//标题
                .setContentText(null == contentText || "".equals(contentText) ? "操作不规范" : contentText)//提示内容
                .setCancelText(null == cancelText || "".equals(cancelText) ? "取消" : cancelText)//取消按钮文本
                .setConfirmText(null == confirmText || "".equals(confirmText) ? "确定" : confirmText)//确认按钮文本
                .showCancelButton(true)
                .setCancelClickListener(new SweetAlertDialog.OnSweetClickListener() {
                    @Override
                    public void onClick(SweetAlertDialog sDialog) {
                        sDialog.dismiss();
                    }
                })
                .setCancelClickListener(new SweetAlertDialog.OnSweetClickListener() {
                    @Override
                    public void onClick(SweetAlertDialog sDialog) {
                        ((Activity)context).finish();
                    }
                })
                .show();
    }

    public static void callDialog(final Context context, String titleText, String contentText, String confirmText, final String phoneNum) {
        new SweetAlertDialog(context, SweetAlertDialog.WARNING_TYPE)
                .setTitleText(null == titleText || "".equals(titleText) ? "提示" : titleText)
                .setContentText(null == contentText || "".equals(contentText) ? "不能为空" : contentText)
                .setConfirmText(confirmText)
                .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
                    @Override
                    public void onClick(SweetAlertDialog sweetAlertDialog) {
                        sweetAlertDialog.dismissWithAnimation();
                        Intent intent = new Intent(Intent.ACTION_DIAL);
                        Uri data = Uri.parse("tel:" + phoneNum);
                        intent.setData(data);
                        context.startActivity(intent);
                    }
                })
                .show();;
    }


}
